package com.example.server.mapper;

import com.example.server.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //根据邮箱查询用户
    @Select("select * from user where email = #{email}")
    User findByEmail(String email);

    //根据昵称查询用户
    @Select("select * from user where username = #{username}")
    User findByUsername(String username);

    //根据id查询用户
    @Select("select * from user where id = #{id}")
    User findById(Integer id);

    //查询所有用户
    @Select("select * from user")
    List<User> selectAll();

    //添加账号
    @Insert("insert into user(username,email,password)"+"values(#{username},#{email},#{password})")
    void insertUser(@Param("email") String email,@Param("password") String password,@Param("username") String username);

    //更新昵称
    @Update("update user set username = #{username} where id = #{id}")
    void updateUsername(@Param("username") String username, @Param("id") Integer id);

    //更新密码
    @Update("update user set password = #{password} where id = #{id}")
    void updatePwd(@Param("password") String password, @Param("id") Integer id);

    //更新登录时间
    @Update("update user set lastLogin = now() where id = #{id}")
    void updateLastLoginTime(@Param("id") Integer id);

    //修改头像
    @Update("update user set avatar = #{avatar} where id = #{id}")
    void updateAvatar(@Param("id") Integer id, @Param("avatar") String avatar);

    //修改身份
    @Update("update user set role = #{role} where id = #{id}")
    void updateRole(@Param("id") Integer id, @Param("role") String role);

    //删除用户
    @Delete("DELETE FROM user WHERE id = #{id}")
    void deleteUser(Integer id);
}
